<template>
  <div class="login-panel">
    <h2>{{ $t('home.name') }}</h2>
    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <el-tab-pane label="帐号" name="account">
          <template #label>
            <el-icon><UserFilled /></el-icon>
            <span class="text">{{ $t('login.name') }}</span>
          </template>
          <login-account ref="accountRef" />
        </el-tab-pane>
        <!-- <el-tab-pane label="手机登录" name="phone">
          <template #label>
            <el-icon><Iphone /></el-icon>
            <span class="text">帐号登录</span>
          </template>
          <login-phone />
        </el-tab-pane> -->
      </el-tabs>
    </div>
    <div class="login-pwd">
      <el-checkbox v-model="isRemPwd" :label="$t('login.rememberPas')" size="large" />
      <span>{{ $t('login.forgetPas') }}</span>
    </div>
    <el-button @click.prevent="loginBtn" class="login-btn" type="primary" size="large">{{
      $t('login.LogInNow')
    }}</el-button>
  </div>
</template>

<script setup lang="ts">
import { localCache } from '@/utils/Cache'
import { ref, watch } from 'vue'
import loginAccount from './login-account.vue'
// import loginPhone from './login-phone.vue'
const isRemPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false)
watch(isRemPwd, (newValue) => {
  localCache.setCache('isRemPwd', newValue)
})
const activeName = ref('account')
// 读取组件的实例 然后利用 InstanceType 返回给 accountRef
const accountRef = ref<InstanceType<typeof loginAccount>>()
function loginBtn() {
  if (activeName.value == 'account') {
    accountRef.value?.returnLoginData(isRemPwd.value)
  } else {
    console.log('手机登录')
  }
}
</script>

<style lang="less" scoped>
.login-panel {
  width: 330px;
  display: flex;
  flex-direction: column;
  align-items: center;
  h2 {
    text-align: center;
    margin-bottom: 20px;
  }
  .tabs {
    width: 100%;
    .text {
      margin-left: 5px;
    }
  }
  .login-pwd {
    width: 100%;
    display: flex;
    align-items: center;
    font-size: 14px;
    justify-content: space-between;
  }
  .login-btn {
    width: 100%;
  }
}
</style>
